export default {
    type: 'form',
    api: {
        url: '/upms/admin/user/update',
        method: 'post',
        requestAdaptor: function (api, context){
            if(context.roleIds && !Array.isArray(context.roleIds)){
                context.roleIds = context.roleIds.split(',');
            }
            return {
              ...api,
              context
            };
        }
    },
    initApi: '/upms/admin/role/grant/list?userId=${id}',
    messages:{
        validateFailed:''
    },
    body:[
    { 
        type: 'hidden',
        name: 'id',
    },
    {
        type: 'group',
        body:[
            {
                type: 'input-text',
                name: 'username',
                label: '用户名',
                static: true
            },
            {
                type: 'input-text',
                name: 'nickName',
                label: '昵称',
                maxLength: 100,
            },
        ]
    },
    {
        type: 'group',
        body:[
            {
                type: 'select',
                name: 'type',
                label: '用户类型',
                source: '/base/dict/options/user-type',
                required: true,
                validationErrors: {
                  isRequired: '请选择用户类型'
                },
                onEvent: {
                    change: {
                        actions: [
                            {
                                actionType: 'setValue',
                                componentId: 'orgId',
                                args: {
                                    value: null
                                }
                            }
                        ]
                    }
                }
            },
            {
                type: 'input-text',
                name: 'phone',
                label: '绑定手机号',
                maxLength: 20,
            },
        ]
    },
    {
        type: 'group',
        body:[
            {
                type: 'select',
                name: 'orgId',
                id: 'orgId',
                label: '所属机构',
                autoComplete: '/upms/admin/org/select?orgName=${term}&orgType=${type}',
                placeholder: '请选择所属机构',
                source: '/upms/admin/org/select?selectedId=${orgId}&orgType=${type}'
            },
            {
                type: 'input-text',
                name: 'orgName',
                label: '机构名称',
                maxLength: 100,
                desc: '管理员、专家直接输入机构名称即可'
            },
        ]
    },
    {
        type: 'group',
        body:[
            {
                type: 'select',
                name: 'roleIds',
                label: '选择角色',
                searchable: true,
                multiple: true,
                labelField: 'roleName',
                valueField: 'id',
                source: '${roles}',
                value: '${selectedRoleIds}',
                clearable: true
            },
            {
                type: 'static',
                name: 'password',
                label: '密码',
                value: '******',
                maxLength: 30,
                validationErrors: {
                  isRequired: '请输入密码'
                }
            },
        ]
    },
    {
        type: 'group',
        body:[
            {
                type: 'switch',
                name: 'status',
                label: '状态',
                onText: '启用',
                offText: '禁用',
                trueValue: 1,
                falseValue: 0,
                required: true
            },
            {
                type: 'switch',
                name: 'mainFlag',
                label: '是否主账号',
                onText: '是',
                offText: '否',
                trueValue: 1,
                falseValue: 0,
                required: true
            },
            {
                type: 'switch',
                name: 'resetPwdFlag',
                label: '是否修改密码',
                onText: '是',
                offText: '否',
                required: true
            },
        ]
    },
    {
        type: 'input-text',
        name: 'remark',
        label: '备注',
        maxLength: 50,
    }
]
}